package com.girant.logger.entity.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.dromara.easyes.annotation.*;
import org.dromara.easyes.annotation.rely.FieldType;
import org.dromara.easyes.annotation.rely.IdType;

//异常日志实体类（映射ES索引 system-logs-*）
@Data
@IndexName(value ="system-logs-*")// 匹配索引名
@JsonIgnoreProperties(ignoreUnknown = true) // 忽略未定义字段
public class ErrorLogDocumentDO {

    //ES默认主键id
    @IndexId(type = IdType.NONE) // 不自定义主键，使用ES默认的_id
    private String id;

    //服务器实例名称
    @IndexField(value = "server_name", fieldType = FieldType.KEYWORD) // 与索引字段名一致
    private String serverName;

    //服务器实例名称标签
    private String serverNameLabel;

    //操作用户ID
    @JsonProperty("operation_user")
    @IndexField(value = "operation_user", fieldType = FieldType.KEYWORD)
    private String operationUser;

    // 操作用户账号
    @JsonProperty("operation_username")
    @IndexField(value = "", fieldType = FieldType.KEYWORD)
    private String operationUsername;//后续添加入库索引名暂定

    //用户昵称
    @JsonProperty("operation_nickname")
    @IndexField(value = "",fieldType = FieldType.KEYWORD)
    private String operationNickname;//后续添加入库索引名暂定

    // 操作时间
    @JsonProperty("log_timestamp")
    @IndexField(
            value = "log_timestamp",
            fieldType = FieldType.DATE,
            dateFormat = "yyyy-MM-dd HH:mm:ss"
    )
    private String operationTime;

    //日志发生时的类名
    @JsonProperty("logger_name")
    @IndexField(value = "logger_name", fieldType = FieldType.KEYWORD)
    private String loggerName;

    //错误信息
    @JsonProperty("log_message")
    @MultiIndexField(
            mainIndexField = @IndexField(
                    value = "log_message",
                    fieldType = FieldType.TEXT,
                    analyzer = "ik_max_word",
                    searchAnalyzer = "ik_smart"
            ),
            otherIndexFields = {
                    @InnerIndexField(suffix = "keyword", fieldType = FieldType.KEYWORD)
            })
    private String errorInfo;

    //异常堆栈信息
    @JsonProperty("stack_trace")
    @MultiIndexField(
            mainIndexField = @IndexField(
                    value = "stack_trace",
                    fieldType = FieldType.TEXT,
                    analyzer = "ik_max_word",
                    searchAnalyzer = "ik_smart"
            ),
            otherIndexFields = {
                    @InnerIndexField(suffix = "keyword", fieldType = FieldType.KEYWORD)
            })
    private String stackTrace;

    //追踪ID
    @JsonProperty("trace_id")
    @IndexField(value = "trace_id",fieldType = FieldType.KEYWORD)
    private String traceId;

    //跨度ID
    @JsonProperty("span_id")
    @IndexField(value = "span_id",fieldType = FieldType.KEYWORD)
    private String spanId;

    //日志级别
    @JsonProperty("log_level")
    @IndexField(value = "log_level",fieldType = FieldType.KEYWORD)
    private String logLevel;

    //客户端浏览器
    @JsonProperty("client_browser")
    @IndexField(value = "client_browser", fieldType = FieldType.KEYWORD)
    private String clientBrowser;

    //客户端版本
    @JsonProperty("client_version")
    @IndexField(value = "client_version", fieldType = FieldType.KEYWORD)
    private String clientVersion;

    // 来源IP
    @JsonProperty("source_ip")
    @IndexField(value = "source_ip", fieldType = FieldType.KEYWORD)
    private String sourceIp;

    private String ClientTypeLabel;
}